package com.ruoyi.framework.config;

import com.google.common.collect.Sets;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger2的接口配置
 *
 * @author ruoyi
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
  /**
   * 系统基础配置
   */
  @Autowired
  private RuoYiConfig ruoYiConfig;

  /**
   * 创建API
   */
  @Bean
  public Docket createRestApi() {
    
    return new Docket(DocumentationType.SWAGGER_2)
        .produces(Sets.newHashSet("application/json"))
        .consumes(Sets.newHashSet("application/json"))
        .protocols(Sets.newHashSet("http", "https"))
        .apiInfo(apiInfo())
        .forCodeGeneration(true)
        .useDefaultResponseMessages(false)
        .select()
        // 指定controller存放的目录路径
        .apis(RequestHandlerSelectors.basePackage("com.ruoyi.project.tool.swagger"))
//                .paths(PathSelectors.ant("/api/v1/*"))
        .paths(PathSelectors.any())
        .build();
  }

  /**
   * 添加摘要信息
   */
  private ApiInfo apiInfo() {
    // 用ApiInfoBuilder进行定制
    return new ApiInfoBuilder()
        .title("标题：若依管理系统_接口文档")
        .description("描述：用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...")
        .version("v1")
        .license("MIT 协议")
        .licenseUrl("http://www.opensource.org/licenses/MIT")
        .contact(new Contact(ruoYiConfig.getName(), null, null))
        .version("版本号:" + ruoYiConfig.getVersion())
        .build();
  }
}
